home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / WindowMaker / WPrefs.app / MenuPreferences.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-03-09  |  6.6 KB  |  246 lines

  1. /* MenuPreferences.c- menu related preferences
  2.  * 
  3.  *  WPrefs - Window Maker Preferences Program
  4.  * 
  5.  *  Copyright (c) 1998 Alfredo K. Kojima
  6.  * 
  7.  *  This program is free software; you can redistribute it and/or modify
  8.  *  it under the terms of the GNU General Public License as published by
  9.  *  the Free Software Foundation; either version 2 of the License, or
  10.  *  (at your option) any later version.
  11.  *
  12.  *  This program is distributed in the hope that it will be useful,
  13.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  *  GNU General Public License for more details.
  16.  *
  17.  *  You should have received a copy of the GNU General Public License
  18.  *  along with this program; if not, write to the Free Software
  19.  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 
  20.  *  USA.
  21.  */
  22.  
  23.  
  24. #include "WPrefs.h"
  25.  
  26. typedef struct _Panel {
  27.     WMFrame *frame;
  28.  
  29.     char *sectionName;
  30.  
  31.     char *description;
  32.  
  33.     CallbackRec callbacks;
  34.     
  35.     WMWindow *win;
  36.  
  37.     WMFrame *scrF;
  38.     WMButton *scrB[5];
  39.     
  40.     WMFrame *aliF;
  41.     WMButton *aliyB;
  42.     WMButton *alinB;
  43.     
  44.     WMFrame *optF;
  45.     WMButton *autoB;
  46.     WMButton *wrapB;
  47.  
  48. } _Panel;
  49.  
  50.  
  51.  
  52. #define ICON_FILE    "menuprefs"
  53. #define SPEED_IMAGE "speed%i"
  54. #define SPEED_IMAGE_S "speed%is"
  55.  
  56. #define MENU_ALIGN1 "menualign1"
  57. #define MENU_ALIGN2 "menualign2"
  58.  
  59.  
  60. static void
  61. showData(_Panel *panel)
  62. {
  63.     WMPerformButtonClick(panel->scrB[GetSpeedForKey("MenuScrollSpeed")]);
  64.     
  65.     if (GetBoolForKey("AlignSubmenus"))
  66.     WMPerformButtonClick(panel->aliyB);
  67.     else
  68.     WMPerformButtonClick(panel->alinB);
  69.     
  70.     WMSetButtonSelected(panel->wrapB, GetBoolForKey("WrapMenus"));
  71.     
  72.     WMSetButtonSelected(panel->autoB, GetBoolForKey("ScrollableMenus"));
  73. }
  74.  
  75.  
  76. static void
  77. storeData(_Panel *panel)
  78. {
  79.     int i;
  80.     
  81.     for (i=0; i<5; i++) {
  82.     if (WMGetButtonSelected(panel->scrB[i]))
  83.         break;
  84.     }
  85.     SetSpeedForKey(i, "MenuScrollSpeed");
  86.  
  87.     SetBoolForKey(WMGetButtonSelected(panel->aliyB), "AlignSubmenus");
  88.  
  89.     SetBoolForKey(WMGetButtonSelected(panel->wrapB), "WrapMenus");
  90.     SetBoolForKey(WMGetButtonSelected(panel->autoB), "ScrollableMenus");
  91. }
  92.  
  93.  
  94. static void
  95. createPanel(Panel *p)
  96. {
  97.     _Panel *panel = (_Panel*)p;
  98.     WMScreen *scr = WMWidgetScreen(panel->win);
  99.  
  100.     WMPixmap *icon;
  101.     int i;
  102.     char *buf1, *buf2;
  103.     char *path;
  104.     
  105.     panel->frame = WMCreateFrame(panel->win);
  106.     WMResizeWidget(panel->frame, FRAME_WIDTH, FRAME_HEIGHT);
  107.     WMMoveWidget(panel->frame, FRAME_LEFT, FRAME_TOP);
  108.     
  109.     
  110.     /***************** Menu Scroll Speed ****************/
  111.     panel->scrF = WMCreateFrame(panel->frame);
  112.     WMResizeWidget(panel->scrF, 235, 90);
  113.     WMMoveWidget(panel->scrF, 25, 20);
  114.     WMSetFrameTitle(panel->scrF, _("Menu Scrolling Speed"));
  115.     
  116.  
  117.     buf1 = wmalloc(strlen(SPEED_IMAGE)+1);
  118.     buf2 = wmalloc(strlen(SPEED_IMAGE_S)+1);
  119.     for (i = 0; i < 5; i++) {
  120.     panel->scrB[i] = WMCreateCustomButton(panel->scrF, WBBStateChangeMask);
  121.     WMResizeWidget(panel->scrB[i], 40, 40);
  122.     WMMoveWidget(panel->scrB[i], 15+(40*i), 30);
  123.     WMSetButtonBordered(panel->scrB[i], False);
  124.     WMSetButtonImagePosition(panel->scrB[i], WIPImageOnly);
  125.     if (i > 0) {
  126.         WMGroupButtons(panel->scrB[0], panel->scrB[i]);
  127.     }
  128.     sprintf(buf1, SPEED_IMAGE, i);
  129.     sprintf(buf2, SPEED_IMAGE_S, i);
  130.     path = LocateImage(buf1);
  131.     if (path) {
  132.         icon = WMCreatePixmapFromFile(scr, path);
  133.         if (icon) {
  134.         WMSetButtonImage(panel->scrB[i], icon);
  135.         WMReleasePixmap(icon);
  136.         } else {
  137.         wwarning(_("could not load icon file %s"), path);
  138.         }
  139.         free(path);
  140.     }
  141.     path = LocateImage(buf2);
  142.     if (path) {
  143.         icon = WMCreatePixmapFromFile(scr, path);
  144.         if (icon) {
  145.         WMSetButtonAltImage(panel->scrB[i], icon);
  146.         WMReleasePixmap(icon);
  147.         } else {
  148.         wwarning(_("could not load icon file %s"), path);
  149.         }
  150.         free(path);
  151.     }
  152.     }
  153.     free(buf1);
  154.     free(buf2);
  155.  
  156.     WMMapSubwidgets(panel->scrF);
  157.  
  158.     /***************** Submenu Alignment ****************/
  159.     
  160.     panel->aliF = WMCreateFrame(panel->frame);
  161.     WMResizeWidget(panel->aliF, 220, 90);
  162.     WMMoveWidget(panel->aliF, 280, 20);
  163.     WMSetFrameTitle(panel->aliF, _("Submenu Alignment"));
  164.     
  165.     panel->alinB = WMCreateButton(panel->aliF, WBTOnOff);
  166.     WMResizeWidget(panel->alinB, 48, 48);
  167.     WMMoveWidget(panel->alinB, 56, 25);
  168.     WMSetButtonImagePosition(panel->alinB, WIPImageOnly);
  169.     path = LocateImage(MENU_ALIGN1);
  170.     if (path) {
  171.     icon = WMCreatePixmapFromFile(scr, path);
  172.     if (icon) {
  173.         WMSetButtonImage(panel->alinB, icon);
  174.         WMReleasePixmap(icon);
  175.     } else {
  176.         wwarning(_("could not load icon file %s"), path);
  177.     }
  178.     free(path);
  179.     }
  180.     panel->aliyB = WMCreateButton(panel->aliF, WBTOnOff);
  181.     WMResizeWidget(panel->aliyB, 48, 48);
  182.     WMMoveWidget(panel->aliyB, 120, 25);
  183.     WMSetButtonImagePosition(panel->aliyB, WIPImageOnly);
  184.     path = LocateImage(MENU_ALIGN2);
  185.     if (path) {
  186.     icon = WMCreatePixmapFromFile(scr, path);
  187.     if (icon) {
  188.         WMSetButtonImage(panel->aliyB, icon);
  189.         WMReleasePixmap(icon);
  190.     } else {
  191.         wwarning(_("could not load icon file %s"), path);
  192.     }
  193.     free(path);
  194.     }
  195.     WMGroupButtons(panel->alinB, panel->aliyB);
  196.     
  197.     WMMapSubwidgets(panel->aliF);
  198.     
  199.     /***************** Options ****************/
  200.     panel->optF = WMCreateFrame(panel->frame);
  201.     WMResizeWidget(panel->optF, 475, 80);
  202.     WMMoveWidget(panel->optF, 25, 130);
  203.     
  204.     panel->wrapB = WMCreateSwitchButton(panel->optF);
  205.     WMResizeWidget(panel->wrapB, 440, 32);
  206.     WMMoveWidget(panel->wrapB, 25, 8);
  207.     WMSetButtonText(panel->wrapB, _("Always open submenus inside the screen, instead of scrolling.\nNote: this is annoying."));
  208.  
  209.     panel->autoB = WMCreateSwitchButton(panel->optF);
  210.     WMResizeWidget(panel->autoB, 440, 20);
  211.     WMMoveWidget(panel->autoB, 25, 45);
  212.     WMSetButtonText(panel->autoB, _("Scroll off-screen menus when pointer is moved over them."));
  213.     
  214.     WMMapSubwidgets(panel->optF);
  215.     
  216.     WMRealizeWidget(panel->frame);
  217.     WMMapSubwidgets(panel->frame);
  218.  
  219.     showData(panel);
  220. }
  221.  
  222.  
  223.  
  224. Panel*
  225. InitMenuPreferences(WMScreen *scr, WMWindow *win)
  226. {
  227.     _Panel *panel;
  228.  
  229.     panel = wmalloc(sizeof(_Panel));
  230.     memset(panel, 0, sizeof(_Panel));
  231.  
  232.     panel->sectionName = _("Menu Preferences");
  233.  
  234.     panel->description = _("Menu usability related options. Scrolling speed,\n"
  235.                "alignment of submenus etc.");
  236.  
  237.     panel->win = win;
  238.     
  239.     panel->callbacks.createWidgets = createPanel;
  240.     panel->callbacks.updateDomain = storeData;
  241.  
  242.     AddSection(panel, ICON_FILE);
  243.  
  244.     return panel;
  245. }
  246.